package LeetCode.binTree_LeetCode;

public class Num026 {
    public boolean isSubStructure(TreeNode A, TreeNode B) {
        if(A == null || B == null){
            return false;
        }
        while(A != null){
            if(A.val == B.val){
                return isSameTree(A,B);
            }else{
                return isSubStructure(A.left,B) || isSubStructure(A.right,B);
            }
        }
        return false;

    }
    public boolean isSameTree(TreeNode p, TreeNode q) {
        if(p == null && q == null){
            return true;
        }
        if(p == null || q == null){
            return false;
        }
        if(p.val != q.val){
            return false;
        }
        return isSameTree(p.left,q.left) && isSameTree(p.right,q.right);
    }
}
